define(function (require) {
	//require('security');
	//app.useModule('security');
	require('arcgis_analysis');
	require(['echarts'], function (es) {
	    echartsObject.hasInitFinsh = true;
        echartsObject.es = es;
        if(echartsObject.initFinshEvent){
            echartsObject.initFinshEvent.forEach(function(e){
            	e(es);
            });
        }
	});

	require('echarts-pie');
	
	require(['plupload','plupload.queue','plupload.i18n'], function () { 
        
   });
	require('ui-upload');

    var app = require('app');
    app.useModule('echarts.pie');
    app.useModule('arcgis.analysis');
    app.useModule('ui.upload');
    //app.useModule('ui.as.files');
    
     app.filter("numlen",function(){
		return function(input,length){
			if(input==null || input=='' || input=="undefined") return input;
			if(!isNaN(input)){
				if(input==parseInt(input) || input>10000) {
					return input;
				}

				if( length==null ) length=4;
				var n=Number(input);
				n=n.toFixed(length);
				n=Number(n);

				return n;
			}else{
				return input;
			}
		};
	});
    
    
    app.controller('analysis_Ctrl', ['$scope','$rootScope', function($scope,$rootScope){
		$rootScope.filterField=function(fn){
			return $rootScope[fn].selectedRow['id'];
			//return f_rcode.mid;
		};
		

				
		/**
		 * gis中的pagesize记录被选中时的效果
		 */
		$scope.gisListSelectObject=function(list,row){
			if(list==null || list.length<1) return;
			if(row==null) row=list[0];
			var selected=!row.selected;
			for(var k=0;k<list.length;k++){
				list[k]["selected"]=false;
			};
			row["selected"]=selected;
			return;
		};

				
				
		/**
		 * 数据分析功能，解析参数，创建分析功能
		 */
		$scope.validDrawAnalysisParan=function(analysisFunction){

			if($rootScope.analysisGeometry==null){
				$.messager.alert("系统提示","请先绘制图形");
				return 
			}
			$scope.validCommonAnalysisParan(analysisFunction);
		};
		/**
		 * 数据分析功能，解析参数，创建分析功能
		 */
		$scope.validGpsAnalysisParan=function(analysisFunction){

			if (window.FileReader) {
				var file = document.getElementById("fileField_dj").files[0];
				if(file==null){
					$.messager.alert("系统提示","请先导入gps文件");
					return;
				}
			} //支持IE 7 8 9 10
			else if (typeof window.ActiveXObject != 'undefined'){
				  //得不到正确的路径   处理了一下
				  var fil=document.getElementById("fileField_dj");
				  fil.select();
				  window.parent.document.body.focus();
				  var filePath = document.selection.createRange().text;
				  if(filePath == ""){
			        	$.messager.alert("系统提示","请选择GPS数据文件！");
			        	return;
			      }
			}else if (document.implementation && document.implementation.createDocument) { 
				    var xmlDoc; 
				    xmlDoc = document.implementation.createDocument("", "", null); 
				    xmlDoc.async = false; 
				    xmlDoc.load(document.getElementById("fileField_dj").value); 
				    if(xmlDoc.xml==null || xmlDoc.xml=='undefined'){
				    	$.messager.alert("系统提示","请选择GPS数据文件！");
			        	return;
				    }
			} else { 
				    $.messager.alert("系统提示","error");
				    return;
			}
			$scope.validCommonAnalysisParan(analysisFunction);
		};

		$scope.analysisLayers={};//分析图层信息
		$scope.analysisSid=null;//分析图层的id
		$scope.selectSid=null;//选中图层的id

		/**
		 * 用户自定义选图
		 * @return {[type]} [description]
		 */
		$scope.selectUserGeomety=function(){
			if($scope.selectSid==null){
				$.messager.alert("系统提示","请先选择选图图层");
				return;
			}
			var sl=$scope.xtLayer.selectedRow;
			//$scope.analysisLayers[$scope.selectSid].hide();
			$rootScope.analysisSelectGeomety(sl.url,[sl.queryLayerId],function(results){
				if($scope.selectSid!=null && $scope.selectSid!=$scope.analysisSid){
					//$scope.analysisLayers[$scope.selectSid].hide();
				}
			});
		}


		/**
		 * 取图方式变化时，隐藏选图图层
		 * @return {[type]} [description]
		 */
		$scope.onchangemethod=function(){
			if($scope.selectSid!=null && $scope.selectSid!=$scope.analysisSid){
				$scope.analysisLayers[$scope.selectSid].hide();
			}
		};

		$scope.onchangeselectmethod=function(){
			if($scope.selectSid!=null && $scope.selectSid!=$scope.analysisSid){
				$scope.analysisLayers[$scope.selectSid].show();
			}
		};


		/**
		 * 取图图层变化时，重新显示图层，添加地图服务，显示图层不显示
		 */
		$rootScope.onchangeXtLayer=function() {
			setTimeout(function(){
				var sl=$scope.xtLayer.selectedRow;
				if(sl==null)return;

				var csid=sl.id;

				if($scope.selectSid!=null && $scope.selectSid!=$scope.analysisSid){
					$scope.analysisLayers[$scope.selectSid].hide();
				}

				if($scope.analysisLayers[csid]==null){
					var mapLayer=$rootScope.addLayer(sl.url,sl.type,null,null,true);
					if(mapLayer==null){
						$.messager.alert("系统提示","地图服务配置错误");
						return;
					}else{
						$scope.selectSid=csid;
						//mapLayer.hide();
						$scope.analysisLayers[csid]=mapLayer;
					}
				}else{
					$scope.selectSid=csid;
					$scope.analysisLayers[csid].show();
				}	
			},300);	
		};

		/**
		 * 分析图层变化时，重新处理图层问题
		 */
		$rootScope.onchangeAnalysisLayer=function() {
			setTimeout(function(){
				var sl=$scope.analysisLayer.selectedRow;
				if(sl==null)return;

				var csid=sl.id;

				if($scope.analysisSid!=null && $scope.analysisSid!=$scope.selectSid){
					$scope.analysisLayers[$scope.analysisSid].hide();
				}

				if($scope.analysisLayers[csid]!=null){
					$scope.analysisSid=csid;
					$scope.analysisLayers[csid].show();
				}else{
					var mapLayer=$rootScope.addLayer(sl.url,sl.type,null,null,true);
					if(mapLayer==null){
						$.messager.alert("系统提示","地图服务配置错误");
						return;
					}else{
						$scope.analysisSid=csid;
						$scope.analysisLayers[csid]=mapLayer;
					}
				}	
			},300);	
		};

		/**
		 * [通用的数据检查功能]
		 * @param  {[type]} analysisFunction [description]
		 * @return {[type]}                  [description]
		 */
		$scope.validCommonAnalysisParan=function(analysisFunction){
			var sl=$scope.analysisLayer.selectedRow;

			if(sl==null){
				$.messager.alert("系统提示","请先选择分析图层");
				return;
			}
			
			var tjlb=$scope.tjlbSearch.selectedRow;
			if(tjlb==null){
				$.messager.alert("系统提示","请先选择统计类别");
				return;
			}else{
				$scope.analysisKeyFieldAlsia=tjlb.aliasName;
				$scope.analysisKeyField=tjlb.name;
			}

			var tjfl=$scope.tjfieldSearch.selectedRow;
			
			if(tjfl==null){
				$.messager.alert("系统提示","请先选择统计字段");
				return;
			}
			var field={};
			field.field=tjfl.name;
			field.Alias=tjfl.aliasName;
			
			var fields=[];
			fields.push(field);
			$scope.analysisResultField=fields;
			
			
			if($scope.analysisLayerBufferDistance==null){
				$.messager.alert("系统提示","请先设置缓冲区大小！");
				return;
			}
			//构造显示函数
			var mustdic=false;
			if(sl.medname!=null && sl.medname!=''){
				mustdic=true;
			}
			var turl=sl.url+"/"+sl.queryLayerId;
			$rootScope.initAnalysisParam(turl,sl.name,'OBJECTID',
				tjlb.name,tjlb.aliasName,
				fields,
				[$scope.analysisLayerBufferDistance],
				sl.medname,null,mustdic,
				$scope.showAnalysisResult);
			analysisFunction();

		};
		
		/**
		 * 获取显示字段问题
		 * @param {Object} id
		 * @param {Object} oncomplete
		 * @param {Object} error
		 */
		$scope.getShowFieldInfo=function(id,oncomplete,error){
			$rootScope.formInit('analShowfield', {
		        keyField:'id',
		        randomFields:['id']
	    	}); 
	    	$rootScope.analShowfield.queryObject["pid:="]=id;
	    	$rootScope.analShowfield.orderObject["order"]=0;
	    	$rootScope.loadData('analShowfield',function(fn,data){
	    		if(oncomplete){
					oncomplete(data);
				}
	    	},function(e){
	    		error(e);
	    	});
		};

		/**
		 * 依据数据进行数据字典转换
		 * @param  {[type]} list       [description]
		 * @param  {[type]} dicname    [description]
		 * @param  {[type]} rooturl    [description]
		 * @param  {[type]} oncomplete [description]
		 * @return {[type]}            [description]
		 */
		$scope.getFieldInfo=function(dicname,rooturl,convert,oncomplete,error){
			if(convert==null){
				convert=false;
			}

			if(convert){
				if(rooturl==null){
					rooturl=getServerBaseUrl();
				}
				var url=rooturl+"/metadata/getEntitys/"+dicname;
				$.ajax({
					url : url,
					type : 'POST',
					data : {},
					timeout : 35000,
					dataType : 'json',
					success : function(data){
						if(oncomplete){
							oncomplete(data);
						}
					},
					error : function(e){
						if(error){
							error(e);
						}
					}
				});
			}else{
				if(oncomplete){
					oncomplete(null);
				}
			}
		};

		$scope.fieldinfo=null;//字典信息
				
		/**
		 * 修改展示效果（数据分析功能）
		 */
		$scope.showAnalysisResult=function(result){
		
			var sl=$scope.analysisLayer.selectedRow;
			var convert=false;
			if(sl.medname!=null && sl.medname!=''){
				convert=true;
			}

			//$scope.getFieldInfo(sl.medname,null,convert,function(list){
			$scope.getShowFieldInfo(sl.id,function(list){

			/*$scope.$apply(function(){*/
				$scope.setSearchOpen(false);
				var analysisShowResult={};
				analysisShowResult.legendlst=[];
				var data=[];
				
				$scope.tableResult=[];
				for(var k=0;k<result.keyLst.length;k++){
					var key=result.keyLst[k];
					var item={};
					item.name=key;
					var fieldDesc=$scope.analysisKeyField+"_DESC";
					for(var j=0;j<result.queryXbLst.length;j++){
						if(result.queryXbLst[j].attributes[$scope.analysisKeyField]==key 
							&& result.queryXbLst[j].attributes[fieldDesc]!=null
							&& result.queryXbLst[j].attributes[fieldDesc]!=''){
							item.name=result.queryXbLst[j].attributes[fieldDesc];
							break;
						}
					}

					var ivalue=result.keyResult[key][$scope.analysisResultField[0].field];
					if(!isNaN(ivalue)){
						ivalue=Number(ivalue);
						ivalue = ivalue.toFixed(4);
						ivalue=Number(ivalue);
					}
					 
					item.value=ivalue;//数据分析字段
					data.push(item);
					analysisShowResult.legendlst.push(item.name);
					
					var tableItem={};
					tableItem[$scope.analysisKeyFieldAlsia]=item.name;
					for(var j=0;j<$scope.analysisResultField.length;j++){
						var kvalue=result.keyResult[key][$scope.analysisResultField[j].field];
						if(!isNaN(kvalue)){
							kvalue=Number(kvalue);
							kvalue = kvalue.toFixed(4); 
							kvalue=Number(kvalue);
						}
						tableItem[$scope.analysisResultField[j].Alias]=kvalue;//数据分析字段
					}
				
					$scope.tableResult.push(tableItem);
				}
				analysisShowResult.data=data;
				$scope.analysisShowResult=$.extend(true, {}, analysisShowResult);
				$scope.resultXb=result.queryXbLst;

				var fieldinfo=[];
				if(list==null || list.length<1){
					for(var key in $scope.resultXb[0].attributes){
						if(key!='ArcgisComputerArea'
							&& key!='ArcgisQueryFeatureComputerArea'
							&& key!='Valuepercentage'){
							var field={};
							field.alias=key;
							field.name=key;
							fieldinfo.push(field);
						}
						
					}

				}else{
					for(var k=0;k<list.length;k++){
						var item=list[k];
						var field={};
						field.alias=item.aliasName;
						if(item.dictionaryName!=null 
							&& item.dictionaryName!=''
							&& item.dictionaryName!='undefined'){
							field.name=item.name+"_DESC";
						}else{
							field.name=item.name;
						}
						field.selected=true;
						fieldinfo.push(field);
						
					}
					
				}
/*					var field_ArcgisComputerArea={};
					field_ArcgisComputerArea.alias='压占面积';
					field_ArcgisComputerArea.name='ArcgisComputerArea';
					field_ArcgisComputerArea.selected=true;
					fieldinfo.push(field_ArcgisComputerArea);

					var field_Valuepercentage={};
					field_Valuepercentage.alias='压占比';
					field_Valuepercentage.name='Valuepercentage';
					field_Valuepercentage.selected=true;
					fieldinfo.push(field_Valuepercentage);

					var field_ArcgisQueryFeatureComputerArea={};
					field_ArcgisQueryFeatureComputerArea.alias='小班计算面积';
					field_ArcgisQueryFeatureComputerArea.name='ArcgisQueryFeatureComputerArea';
					field_ArcgisQueryFeatureComputerArea.selected=true;
					fieldinfo.push(field_ArcgisQueryFeatureComputerArea);*/

				$scope.fieldinfo=fieldinfo;//处理字段主键问题

				//处理字段历史展示问题
				var sl=$scope.analysisLayer.selectedRow;
				if(sl==null)return;
				var csid=sl.id;
				if($scope.gisFields[csid]==null){
					$scope.gisFields[csid]={};
				}
				if($scope.gisFields[csid].showfieldinfo!=null){
					$scope.showfieldinfo=$.extend(true,[],$scope.gisFields[csid].showfieldinfo);
					for(var k=0;k<$scope.fieldinfo.length;k++){
						var unfind=true;
						for(var j=0;j<$scope.showfieldinfo.length;j++){
							if($scope.showfieldinfo[j].name==$scope.fieldinfo[k].name){
								unfind=false;
								break;
							}
						}
						if(unfind){
							$scope.fieldinfo[k].selected=false;
						}

					}
				}else{
					$scope.showfieldinfo=[];
					for(var k=0;k<fieldinfo.length;k++){
						var field=fieldinfo[k];
						if(field.selected){
							$scope.showfieldinfo.push(field);
						}
					}
					$scope.gisFields[csid].showfieldinfo=$.extend(true,[],$scope.showfieldinfo);
				}
				
				//启用页面的选中效果方法**********************************
				
				var infoTemplate=$scope.setSearchInfo($scope.showfieldinfo,sl.name);
				for(var k=0;k<$scope.resultXb.length;k++){
					var feature = $scope.resultXb[k];
					feature.geometry.spatialReference = $rootScope.gisObject.mapwkid;
					if(!feature.attributes){
						feature.attributes = {};
					}
					if(!feature.attributes._guid){
						feature.attributes._guid = $rootScope.getGUID();
					}
                    for(var i in feature.attributes) {
						if(feature.attributes[i]==='Null'){
                            feature.attributes[i] = '';
						}
                    }
                    //TODO 这里需要处理一下
		          	$rootScope.addFeatureSelectGraphic(feature, infoTemplate);
				}
				// 启用map.graphics的鼠标事件
		    	$rootScope.gisObject.map.graphics.enableMouseEvents();
				var mouseOverHandle = dojo.connect($rootScope.gisObject.map.graphics, "onMouseOver", function (evt){
			    	var graphic = evt.graphic;
			    	if(!graphic.attributes){
			    		return;
			    	}
			    	$rootScope.gisObject.map.setMapCursor("pointer");
			    	if(graphic.attributes.$isFeature && graphic.attributes.$isFeature==true){
			    		$rootScope.highFeatureSelectGraphicEx(graphic);
			    	}
			    });
			    var mouseOutHandle = dojo.connect($rootScope.gisObject.map.graphics, "onMouseOut", function (evt){
			       	var graphic = evt.graphic;
			    	if(!graphic.attributes){
			    		return;
			    	}
			    	$rootScope.gisObject.map.setMapCursor("default");
			    	if(graphic.attributes.$isFeature && graphic.attributes.$isFeature==true){
			    		$rootScope.featureSelectGraphicEx(graphic);
			    	}
			    });
		       	var clickHandle = dojo.connect($rootScope.gisObject.map.graphics, "onClick", function (evt){
		    		var graphic = evt.graphic;
		    		if(!graphic.attributes){
			    		return;
			    	}
		    		if(graphic.attributes.$isFeature && graphic.attributes.$isFeature==true){
			    		$rootScope.showInfoWindowEx(graphic);
			    	}
		    	});
		    	dojo.disconnect(mouseOverHandle);
		    	dojo.disconnect(mouseOutHandle);
		    	dojo.disconnect(clickHandle);
		    	//设置地图视图范围
				//var rExtent = $rootScope.getMaxExtent($scope.resultXb);
				//$rootScope.gisObject.map.setExtent(rExtent);

				// 显示第一个节点
	       		//$rootScope.showInfoWindow($scope.resultXb[0].attributes._guid);
			/*});*/
			});
		};

		$scope.gisFields={};

		$scope.resetShowField=function(fieldinfo){
			var showfieldinfo=[];
			for(var k=0;k<fieldinfo.length;k++){
				var field=fieldinfo[k];
				if(field.selected){
					showfieldinfo.push(field);
				}
			}
			$scope.showfieldinfo=showfieldinfo;
			$scope.showSelectField=false;

			var sl=$scope.analysisLayer.selectedRow;
			if(sl==null)return;
			var csid=sl.sid;
			if($scope.gisFields[csid]==null){
				$scope.gisFields[csid]={};
			}
			$scope.gisFields[csid].showfieldinfo=$.extend(true,[],showfieldinfo);
		};

		/**
		 * 全或者反选择字段问题
		 * @param  {[type]} fieldinfo [description]
		 * @param  {[type]} v         [description]
		 * @return {[type]}           [description]
		 */
		$scope.selectAllField=function(fieldinfo,v){
			for(var k=0;k<fieldinfo.length;k++){
				fieldinfo[k].selected=v;
			}
		};
				
		/**
		 * 初始化arcgis属性查询条件
		 * @param queryForm 查询对象
		 * @param url 地图服务地址
		 * @param ibox 弹窗页面id
		 * @param pagesize 单个页面最大查询结果数
		 * @param idfield 结果主键字段（存在OBJECT字段就不需要再次设置了）
		 */
		$scope.initGisAttributeQueryform=function(queryForm,url,pagesize,idField){
			if(pagesize==null){
				pagesize=3;
			}
			if(idField==null){
				idField="OBJECT";
			}
			$rootScope.initAttSearch(queryForm,null);
			$rootScope.gisObject.searchParameter[queryForm].searchPageSize=pagesize;
			$rootScope.gisObject.searchParameter[queryForm].keyName=idField;
			$rootScope.gisObject.searchParameter[queryForm].keyNames=[idField];
			$rootScope.gisObject.searchParameter[queryForm].url=url+"/0";
			$rootScope.gisObject.searchParameter[queryForm].selectFields=["*"];
		};
				
		/**
		 * gis中的pagesize记录被选中时的效果
		 */
		$scope.gisListSelectObject=function(list,row){
			/*if(list==null || list.length<1) return;
			if(row==null) row=list[0];*/
			var selected=!row.selected;
			/*for(var k=0;k<list.length;k++){
				list[k]["selected"]=false;
			};*/
			row["selected"]=selected;
			return;
		}
				
		/**
		 * 定位功能
		 */
		$scope.gisDirectObject=function(list){
			var graphics=[];
			for(var k=0;k<list.length;k++){
				var f=list[k];
				if(f.selected){
					graphics.push(f);
					//$rootScope.addFeaturePopGraphic(f,(k+1));
					$rootScope.addFeatureSelectGraphic(f)
				}
				
			};
			if(graphics.length<1){
				$.messager.alert("系统提示","没有选中的小班");
				return ;
			}
			//设置地图视图范围
			var rExtent = $rootScope.getMaxExtent(graphics);
	    	$rootScope.gisObject.map.setExtent(rExtent);
		};
		
		/**
		 * 定位到小班位置
		 * @param {Object} row
		 */
		$scope.dirToxb=function(row){
			var graphics=[];
			graphics.push(row);
			$rootScope.addFeatureSelectGraphic(row);
			var rExtent = $rootScope.getMaxExtent(graphics);
	    	$rootScope.gisObject.map.setExtent(rExtent);
		};
		
		$rootScope.onFileUpload=function(fileInfo){
			$scope.uploaddata=null;
			console.log(fileInfo);
			
			if(fileInfo!=null && fileInfo.graphic!=null){
				var graphic=fileInfo.graphic;
				var arcgisGemetrys=null;
				var go = $rootScope.gisObject;
				var srf=go.dlwkid.wkid;
				if(graphic.graphicType=='POLYG'){
					arcgisGemetrys=$scope.getArcgisPlogyGeomety(graphic,srf);
				}else if(graphic.graphicType=='LINE'){
					arcgisGemetrys=$scope.getArcgisPolyLinesGeomety(graphic,srf);
				}else if(graphic.graphicType=='POINT'){
					arcgisGemetrys=$scope.getArcgisPointsGeomety(graphic,srf);
				}
				//图形几何校正
		        $rootScope.gisObject.geometryService.simplify(arcgisGemetrys,function(simplifiedGeometries){
		        	$rootScope.clearGraphics();
					$rootScope.analysisGeometry =simplifiedGeometries[0];
					var guid = $rootScope.getGUID();
					$rootScope.addPolygonGraphic($rootScope.analysisGeometry,guid);
					//$scope.addAnalysisDefaultGraphic($rootScope.analysisGeometry,guid);
					//设置地图视图范围
					var feature={};
					feature.geometry=$.extend(true, {}, $rootScope.analysisGeometry);
					var rExtent = $rootScope.getMaxExtent([feature]);
			    	$rootScope.gisObject.map.setExtent(rExtent);
		        },function(e){
		        	$.messager.alert("系统提示","不能分析,请检查文件中GPS点串格式！");
			        return;
		        });
			}
		};
		
		/**
		 * 添加graphic
		 * geometry 线对象，guid 全局唯一值
		 */
		$scope.addAnalysisDefaultGraphic =function(geometry, guid){
			var gh = $rootScope.gisObject.map.graphics;
			if(!gh){
				return null;
			}
			guid = guid ? guid : $rootScope.getGUID();

			var outlineSyml = new esri.symbol.SimpleLineSymbol(
			esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([
					$rootScope.getDrawStyle().fillColor.r,
						$rootScope.getDrawStyle().fillColor.g,
						$rootScope.getDrawStyle().fillColor.b,
						$rootScope.getDrawStyle().fillOpacity]),
				$rootScope.getHighLightDefaultStyle().strokeWidth);
				
			var fillSymbol = new esri.symbol.SimpleFillSymbol(
				esri.symbol.SimpleFillSymbol.STYLE_SOLID,
				outlineSyml, new dojo.Color([
						254,
						0,
						0,
						0.2]));
			// 先添加绘制图形
			var graphic = new esri.Graphic(geometry, fillSymbol);
			if(!graphic.attributes){
				graphic.attributes = {};
			}
			graphic.attributes.$guid = guid;
			gh.add(graphic);
			return graphic;
		};
		
		
        
    	/**
		* polygon点串转换为arcGis图形，支持多polygon,格式如下 图形与图形之间"_" 同一图形多环";" 点之间"," 同一点经纬度间"
		* "空格 sfr:空间参考
		*/
		$scope.getArcgisPlogyGeomety = function(graphic, srf) {
		  	// 返回的图形数组
		  	var goeArr = new Array();
		 
		  	var points = new Array();
		  	// 遍历不同图形
		  	var tGoe = new esri.geometry.Polygon(srf);
		  	var rings = new Array();
		  	for (var i = 0; i < graphic.points.length; i++){
		  		
		  		var ipoint=graphic.points[i];
		  		p = new esri.geometry.Point(Number(ipoint.x),Number(ipoint.y), srf);
  				if(!isNaN(p.x)&&!isNaN(p.y)){
  					rings.push(p);
  				}else{
  					throw new Error("数据格式不正确，请检查坐标！");
  				}
		  	}
		  	tGoe.addRing(rings);
		  	goeArr.push(tGoe);
		  	return goeArr;
		};
	  	
	  	/**
	  	* polyLine点串转换为arcGis图形，支持多polyLine,格式如下 图形与图形之间"_" 点之间"," 同一点经纬度间" "空格
	  	* 
	  	* @param pointStr
	  	*            点串
	  	* @param sfr空间参考
	  	*/
	  	$scope.getArcgisPolyLinesGeomety = function(graphic, srf) {
	  		// 返回的图形数组
	  		var goeArr = new Array();
	  		var geoPointArr = pointStr.substr(pointStr.indexOf(":")+1).split("_");
	  		var tGoe = new esri.geometry.Polyline(srf);
	  		var points = new Array();
	  		for (var i = 0; i < graphic.points.length; i++){
		  		
		  		var ipoint=graphic.points[i];
		  		p = new esri.geometry.Point(Number(ipoint.x),Number(ipoint.y), srf);
  				if(!isNaN(p.x)&&!isNaN(p.y)){
  					points.push(p);
  				}else{
  					throw new Error("数据格式不正确，请检查坐标！");
  				}
		  	}
	  		tGoe.addPath(points);
	  		goeArr.push(tGoe);
	  		return goeArr;
	  	};
	
	  	/**
	  	 * point点串转换为arcGis图形， 支持多个point, 格式如下 图形与图形之间"_" 点之间"," 同一点经纬度间" "空格
	  	 * sfr:空间参考
	  	 */
	  	$scope.getArcgisPointsGeomety = function(graphic, srf) {
	  		// 返回的图形数组
	  		var goeArr = new Array();
  			p = new esri.geometry.Point(Number(graphic.x), Number(graphic.x),
  						srf);
  			goeArr.push(p);
	  		return goeArr;
	  	};
	  	
	  	/**
		 * 设置查询信息模板
		 */
		$scope.setSearchInfo =function(showfieldinfo,infoTemplateTitle){
			if(!showfieldinfo) return null;
			//信息模板
          	var infoTemplate = new esri.InfoTemplate();
          	//设置Title
          	var title = infoTemplateTitle;
          	if(title==null){
          		title="小班";
          	}
          	title=title+"";
          	title = title.replace(/~/gm,'$');
          	infoTemplate.setTitle(title);
          	//设置Content
          	var content = '';
          	for(var k=0;k<showfieldinfo.length;k++){
          		var field=showfieldinfo[k];
          		content = content + '<tr> <td width="40%" style="text-align: right;" >'+field.alias+'</td> <td width="60%" style="text-align: left;">~{'+field.name+'}</td> </tr>';
          		/*if(content == null || content == ""){
	          		}else{
	          		content =content + '<br/><b>'+field.alias+': </b>~{'+field.name+'}';
	          	}*/
          	}
          	
          	var head='<div class="container"><table width="100%" class="table-b" style="table-layout:fixed">';
          	var foot="</table></div>";
          	content=head+content+foot;
          	content = content.replace(/~/gm,'$');
          	infoTemplate.setContent(content);
          	//设置infoWindow的尺寸
          	$rootScope.gisObject.map.infoWindow.resize(240, 260);
          	
          	return infoTemplate;
        };
        
        $scope.showInfoWindowAndResize=function(key){
			$rootScope.showInfoWindow(key);
			var w=240;
			var h=260;
			if(w!=null && h!=null){
				$rootScope.gisObject.map.infoWindow.resize(w, h);
			};
		};
		
	}]);
});